package com.yn.common.enums;

import lombok.Getter;

/**
 * 生活能力枚举
 * 对应数据库 living_ability 字段：0-完全自理 1-部分自理 2-完全不能自理
 */
@Getter
public enum LivingAbilityEnum {

    FULLY_INDEPENDENT(0, "完全自理"),
    PARTIALLY_INDEPENDENT(1, "部分自理"),
    COMPLETELY_DEPENDENT(2, "完全不能自理");

    private final Integer code;
    private final String name;

    LivingAbilityEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据 code 获取枚举实例
     * @param code 生活能力编码
     * @return 对应的枚举，无匹配返回 null
     */
    public static LivingAbilityEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (LivingAbilityEnum abilityEnum : LivingAbilityEnum.values()) {
            if (abilityEnum.getCode().equals(code)) {
                return abilityEnum;
            }
        }
        return null;
    }
}